;----------------------------------------------------------------------------
; File name:	LAYER.SH			Revision date:	1997.08.13
; Authors:	Peter Rottengatter  &		Creation date:	1997.03.26
;		Ronald Andersson		Version:	1.01
;----------------------------------------------------------------------------
; Purpose:	High level StinG protocol interfacing
;		Header file included in assembly
;----------------------------------------------------------------------------
;Required header declarations:
;
;	.include	"uran\STRUCT.SH"
;	.include	"sting\TRANSPORT.SH"
;	.include	"sting\LAYER.SH"
;
;copy the above to the header of your program and 'uncomment' the includes
;----------------------------------------------------------------------------
;
;#define MODULE_DRIVER    "MODULE_LAYER"
;
;----------------------------------------------------------------------------
;
MAX_HANDLE	equ	64	;Number of handles assigned by PRTCL_request
;
;----------------------------------------------------------------------------
;	High level protocol module descriptor.
;
	struct 	LAYER
	char_p		LAYER_name		; Name of layer
	char_p		LAYER_version		; Version of layer in xx.yy format
	uint32		LAYER_flags		; Private data
	uint16		LAYER_date		; Compile date in GEMDOS format
	char_p		LAYER_author		; Name of programmer
	int16		LAYER_stat_dropped	; Statistics of dropped data units
	struct_p	LAYER_next		; Next layer in driver chain
	d_end	LAYER
;
;----------------------------------------------------------------------------
;	CN functions structure for TCP and UDP
;
	struct	CN_FUNCS
	func_p	CNkick		;int16	cdecl	(* CNkick) (void *);
	func_p	CNbyte_count	;int16	cdecl	(* CNbyte_count) (void *);
	func_p	CNget_char	;int16	cdecl	(* CNget_char) (void *);
	func_p	CNget_NDB	;NDB	cdecl	(* CNget_NDB) (void *);
	func_p	CNget_block	;int16	cdecl	(* CNget_block) (void *, void *, int16);
	func_p	CNgetinfo	;CIB;	cdecl	(* CNgetinfo) (void *);
	func_p	CNgets		;int16	cdecl	(* CNgets) (void *, char *, int16, char);
	d_end	CN_FUNCS
;
;----------------------------------------------------------------------------
;	Module driver structure / functions
;
	struct	STX_head
	char_p	STX_module;		; Specific string that can be searched for
	char_p	STX_author;		; Any string
	char_p	STX_version;		; Format `00.00' Version:Revision
	func_p	STX_set_dgram_ttl	;void	cdecl	(* set_dgram_ttl) (IP_DGRAM *);
	func_p	STX_check_dgram_ttl	;int16	cdecl	(* check_dgram_ttl) (IP_DGRAM *);
	func_p	STX_load_routing_table	;int16	cdecl	(* load_routing_table) (void);
	func_p	STX_set_sysvars		;int32	cdecl	(* set_sysvars) (int16, int16);
	func_p	STX_query_chains	;void	cdecl	(* query_chains) (void **, void **, void **);
	func_p	STX_IP_send		;int16	cdecl	(* IP_send) (uint32, uint32, uint8, uint16, uint8, uint8, uint16, void *, uint16, void *, uint16);
	func_p	STX_IP_fetch		;IP_DGRAM * cdecl	(* IP_fetch) (int16);
	func_p	STX_IP_handler		;int16	cdecl	(* IP_handler) (int16, int16 cdecl (*) (IP_DGRAM *), int16);
	func_p	STX_IP_discard		;void	cdecl	(* IP_discard) (IP_DGRAM *, int16);
	func_p	STX_PRTCL_announce	;int16	cdecl	(* PRTCL_announce) (int16);
	func_p	STX_PRTCL_get_parameters;int16	cdecl	(* PRTCL_get_parameters) (uint32, uint32 *, int16 *, uint16 *);
	func_p	STX_PRTCL_request	;int16	cdecl	(* PRTCL_request) (void *, CN_FUNCS *);
	func_p	STX_PRTCL_release	;void	cdecl	(* PRTCL_release) (int16);
	func_p	STX_PRTCL_lookup	;void;	cdecl	(* PRTCL_lookup) (int16, CN_FUNCS *);
	func_p	STX_TIMER_call		;int16	cdecl	(* TIMER_call) (void cdecl (*) (void), int16);
	func_p	STX_TIMER_now		;int32	cdecl	(* TIMER_now) (void);
	func_p	STX_TIMER_elapsed	;int32	cdecl	(* TIMER_elapsed) (int32);
	d_end	STX_head
;
	.import	stx			;extern STX *stx;
;
;----------------------------------------------------------------------------
;	Definitions of module driver function macros for direct use
;----------------------------------------------------------------------------
;	Submacros are used to make the interface flexible and powerful
;
;sub_stx.mode	is used to implement all STX functions, and uses submacros
;		sub_sub_stx as well as some of URAn_SYS.SH.  It gives argument
;		count check for all macros, and allows indirection of pointers.
;----------------------------------------------------------------------------
;
.MACRO	sub_stx.mode	function,arg_count,arg_flags,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11
	CDECL_args.mode	arg_flags,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11
	sub_sub_stx	STX_&function
	CDECL_cleanargs	function,arg_count
.ENDM	sub_stx
;
;-------------------------------------
;
.MACRO	sub_sub_stx	stx_function
	move.l	stx,a0
	move.l	stx_function(a0),a0
	jsr	(a0)
.ENDM	sub_sub_stx
;
;----------------------------------------------------------------------------
;
.MACRO	set_dgram_ttl.mode	dgram_p
	sub_stx.mode	set_dgram_ttl,1,3,dgram_p
.ENDM	set_dgram_ttl
;
.MACRO	check_dgram_ttl.mode	dgram_p
	sub_stx.mode	check_dgram_ttl,1,3,dgram_p
.ENDM	check_dgram_ttl
;
.MACRO	load_routing_table
	sub_stx	load_routing_table,0,0
.ENDM	load_routing_table
;
.MACRO	set_sysvars	active_f,count_5ms
	sub_stx	set_sysvars,2,5,active_f,count_5ms
.ENDM	set_sysvars
;
.MACRO	query_chains.mode	port_p,driver_p,layer_p
	sub_stx.mode	query_chains,3,$3F,port_p,driver_p,layer_p
.ENDM	query_chains
;
.MACRO	IP_send.mode	s_IP,d_IP,tos,unfrag,ttl,proto,id,data_p,datalen,opt_p,optlen
	sub_stx.mode	IP_send,11,$1DD04A,s_IP,d_IP,tos,unfrag,ttl,proto,id,data_p,datalen,opt_p,optlen
.ENDM	IP_send
;
.MACRO	IP_fetch	protocol
	sub_stx	IP_fetch,1,1,protocol
.ENDM	IP_fetch
;
.MACRO	IP_handler.mode	protocol,handler_p,install_code
	sub_stx.mode	IP_handler,3,$1D,protocol,handler_p,install_code
.ENDM	IP_handler
;
.MACRO	IP_discard.mode	dgram_p,all_f
	sub_stx.mode	IP_discard,2,7,dgram_p,all_f
.ENDM	IP_discard
;
.MACRO	PRTCL_announce	protocol
	sub_stx	PRTCL_announce,1,1,protocol
.ENDM	PRTCL_announce
;
.MACRO	PRTCL_get_parameters.mode	remote_IP,local_IP_p,ttl_p,mtu_p
	sub_stx.mode	PRTCL_get_parameters,4,$FE,remote_IP,local_IP_p,ttl_p,mtu_p
.ENDM	PRTCL_get_parameters
;
.MACRO	PRTCL_request.mode	cn_data_p,cn_funcs_p
	sub_stx.mode	PRTCL_request,2,$F
.ENDM	PRTCL_request
;
.MACRO	PRTCL_release	cn_handle
	sub_stx	PRTCL_release,1,1,cn_handle
.ENDM	PRTCL_release
;
.MACRO	PRTCL_lookup.mode	cn_handle,cn_funcs_p
	sub_stx.mode	PRTCL_lookup,2,$D,cn_handle,cn_funcs_p
.ENDM	PRTCL_lookup
;
.MACRO	TIMER_call.mode	handler_p,install_code
	sub_stx.mode	TIMER_call,2,7,handler_p,install_code
.ENDM	TIMER_call
;
.MACRO	TIMER_now
	sub_stx	TIMER_now,0,0
.ENDM	TIMER_now
;
.MACRO	TIMER_elapsed	old_time
	sub_stx	TIMER_elapsed,1,2,old_time
.ENDM	TIMER_elapsed
;
;----------------------------------------------------------------------------
; End of file:	LAYER.SH
;----------------------------------------------------------------------------
